{extend name="app/shop/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>秒杀时段名称将会显示在秒杀列表页的时间段内</li>
			<li>秒杀时间-时：可填入00-23的整数（如果为个位数，需在前面加上0，比如：01）</li>
			<li>秒杀时间-分/秒：可填入00-59的整数（如果为个位数，需在前面加上0，比如：01）</li>
		</ul>
	</div>
</div>

<div class="layui-form ns-form">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>秒杀场次名称：</label>
		<div class="layui-input-block">
			<input type="text" name="name" lay-verify="required" value="{$time_info.name}" autocomplete="off" class="layui-input ns-len-long">
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">开始时间：</label>
			
			<div class="layui-input-inline">
				<input type="text" name="start_hour" value="{$time_info.start_hour}" lay-verify="timeHour" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">时</div>
			
			<div class="layui-input-inline">
				<input type="text" name="start_minute" value="{$time_info.start_minute}" lay-verify="timeMinSend" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">分</div>
			
			<div class="layui-input-inline">
				<input type="text" name="start_second" value="{$time_info.start_second}" lay-verify="timeMinSend" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">秒</div>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">结束时间：</label>
			
			<div class="layui-input-inline">
				<input type="text" name="end_hour" value="{$time_info.end_hour}" lay-verify="timeHour" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">时</div>
			
			<div class="layui-input-inline">
				<input type="text" name="end_minute" value="{$time_info.end_minute}" lay-verify="timeMinSend" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">分</div>
			
			<div class="layui-input-inline">
				<input type="text" name="end_second" value="{$time_info.end_second}" lay-verify="timeMinSend" autocomplete="off" class="layui-input ns-len-short">
			</div>
			<div class="layui-form-mid">秒</div>
		</div>
	</div>
	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>
	<input type="hidden" name="id" value="{$time_info.id}" />
</div>

{/block}
{block name="script"}
<script>
	layui.use('form', function() {
		var form = layui.form,
			repeat_flag = false; //防重复标识
		form.render();

		// 表单提交监听
		form.on('submit(save)', function(data) {
			if (repeat_flag) return;
			repeat_flag = true;
			$.ajax({
				url: ns.url("seckill://shop/seckill/edit"),
				data: data.field,
				type: "post",
				dataType: "JSON",
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.confirm('编辑成功', {
							title: '操作提示',
							btn: ['返回列表', '继续操作'],
							yes: function() {
								location.href = ns.url("seckill://shop/seckill/lists");
							},
							btn2: function() {
								location.reload();
							}
						});
					} else {
						layer.msg(res.message);
					}
				}
			});
		});
		
		form.verify({
			timeHour: function(value) {
				if (!new RegExp("^0|[1-9]|1[0-9]|2[0-3]$").test(value)) {
					return '时段范围为0-23，且只能是整数';
				}
			},
			timeMinSend: function(value) {
				if (!new RegExp("^(?:0|[0-5][0-9]?)$").test(value)) {
					return '分秒范围为0-59，且只能是整数';
				}
			}
		});
	});

	function back() {
		location.href = ns.url("seckill://shop/seckill/lists");
	}
</script>
{/block}